#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>

char* newenv = (char*)"MYVAL3=3333333";
extern char** environ;

int main()
{
    printf("我的程序开始运行！\n");

    if(fork() == 0)
    {
        printf("pid->%d\n", getpid());
        sleep(1);

        char* const argv[] = 
        {
            (char* const)"other",
            (char* const)"-a",
            (char* const)"-b",
            NULL
        };
        
        char* const addenv[] = 
        {
            (char* const)"MYVAL1=1111111",
            (char* const)"MYVAL2=2222222",
            (char* const)"MYVAL3=3333333",
            (char* const)"MYVAL4=4444444",
            (char* const)"MYVAL5=5555555",
            NULL
        };
        int i = 0;
        for(; addenv[i]; i++)
        {
            putenv(addenv[i]);
        }
        execvpe("./other", argv, environ);
        //putenv(newenv);
        //execv("./other", argv);

        //execlp("/usr/bin/ls", "ls","-a", "-l", NULL);
        //execl("./other", "other", NULL);
        exit(0);
    }
    waitpid(-1, NULL, 0);
    printf("我的程序运行结束了！\n");

    return 0;
}
